package com.ltmonitor.web.controller.command;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ltmonitor.entity.TerminalCommand;
import com.ltmonitor.service.JT808Constants;
import com.ltmonitor.web.util.JsonMessage;

/**
 * 数据透明传输下行
 * 
 * @author DELL
 * 
 */
@Controller
@RequestMapping("/transparentSend")
public class TransparentSendAction extends TerminalCommandAction {

	@RequestMapping("/view.action")
	public String view(long vehicleId, Model m) {
		m.addAttribute("vehicleId", vehicleId);
		return "/command/transparentSend";
	}

	/**
	 * 发送透明传输指令
	 * @param vehicleId
	 * @param msgType 消息类型
	 * @param msgFormat  格式 hex 表示16进制，txt表示文本
	 * @param msgContent 消息内容
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/send.action")
	public JsonMessage execute(long vehicleId, int msgType, String msgFormat, String msgContent) {

		TerminalCommand tc = new TerminalCommand();
		try {
			tc.setCmdType(JT808Constants.CMD_TRANS);
			tc.setCmdData(msgFormat + ";" + msgType + ";" + msgContent);
			tc.setVehicleId(vehicleId);
			SendCommand(tc);
			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			return json(false, ex.getMessage());
		}

	}

}
